<test>
    <settings>
        <allow_aggregate_partitions_independently>1</allow_aggregate_partitions_independently>
        <force_aggregate_partitions_independently>1</force_aggregate_partitions_independently>
        <max_number_of_partitions_for_independent_aggregation>256</max_number_of_partitions_for_independent_aggregation>
        <max_memory_usage>0</max_memory_usage>
        <max_partitions_per_insert_block>256</max_partitions_per_insert_block>
    </settings>

    <substitutions>
        <substitution>
            <name>size</name>
            <values>
                <!-- <value>10000</value> -->
                <value>100000</value>
                <value>1000000</value>
                <value>10000000</value>
                <!-- <value>100000000</value> -->
            </values>
        </substitution>

        <substitution>
            <name>partitions</name>
            <values>
                <!-- <value>2</value> -->
                <!-- <value>4</value> -->
                <!-- <value>8</value> -->
                <value>16</value>
                <value>32</value>
                <value>64</value>
                <!-- <value>128</value> -->
                <!-- <value>256</value> -->
            </values>
        </substitution>
    </substitutions>

    <create_query>create table t_{size}_{partitions}(a UInt64) engine=MergeTree order by a partition by sipHash64(a) % {partitions}</create_query>

    <fill_query>insert into t_{size}_{partitions} select * from numbers_mt({size})</fill_query>

    <fill_query>optimize table t_{size}_{partitions} final</fill_query>

    <query>select a from t_{size}_{partitions} group by a format Null</query>

    <query>select a from t_{size}_{partitions} group by a format Null settings optimize_aggregation_in_order = 1</query>

    <drop_query>drop table t_{size}_{partitions}</drop_query>
</test>
